#include <queue>
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

struct Entity {
    int freq;
    char c;
    const Entity *left, *right;
    Entity(char _c, int _f): c(_c), freq(_f), left(NULL), right(NULL) {}
    Entity(): Entity(0, 0) {}
};

Entity* huffman(vector<Entity*> & C);

int main() {
    vector<Entity*> es;
    int N = 6;
    char c; int freq;
    for (int i = 0; i < N; i++) {
        cin >> c >> freq;
        es.push_back(new Entity(c, freq));
    }
    Entity * e = huffman(es);
    return 0;
}




struct cmp {
    bool operator()(const Entity *e1, const Entity *e2) {
        return e1->freq > e2->freq;
    }
};

Entity* huffman(vector<Entity*> & C) {
    priority_queue<Entity*, vector<Entity*>, cmp> q(C.begin(), C.end());
    while (q.size() > 1) {
        const 
        Entity *e1 = q.top(); q.pop();
        Entity *e2 = q.top(); q.pop();
        Entity *e = new Entity(); e->freq = e1->freq + e2->freq;
        e->left = e1; e->right = e2;
        q.push(e);
    }
    return q.top();
}